/**
 * Select选择器
 */
import React from 'react';
import { Select, Spin } from 'antd';

const { Option } = Select;

const SelectCustom = React.forwardRef(({ dataSource, loading = false, value, onChange, ...rest }, ref) => (
    <Spin spinning={loading}>
        <Select
            ref={ref}
            style={{ width: '100%' }}
            dropdownStyle={{ maxHeight: 250, overflow: 'auto' }}
            getPopupContainer={trigger => trigger.parentElement}
            placeholder="请选择"
            allowClear
            onChange={onChange}
            value={value}
            {...rest}
        >
            {dataSource?.map(item => (
                <Option value={item.value} key={item.value} {...item}>
                    {item.label}
                </Option>
            ))}
        </Select>
    </Spin>
));

export default SelectCustom;
